package yzx.fileutil;

import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;

public class WelcomeActivity extends AppCompatActivity{


    private Handler mHandler = new Handler();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        if(!checkSDOrShowDialog())
            return ;
        mHandler.postDelayed(new Runnable() {
            public void run() {
                if(isFinishing())
                    return ;
                MainActivity.launch(WelcomeActivity.this);
                finish();
            }
        }, 100);
    }

    @Override
    protected void onDestroy() {
        mHandler.removeCallbacksAndMessages(null);
        super.onDestroy();
    }


    private boolean checkSDOrShowDialog(){
        if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){
            return true;
        }
        new AlertDialog.Builder(this).setMessage("手机没有内存卡!").setNegativeButton("确定", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        }).setTitle("提示").setCancelable(false).show();
        return false;
    }


}
